<template>
	<view>
		<view style="border-top: 2rpx solid #F7F7F7;margin: 35rpx 0 30rpx;"></view>
		<view style="display: flex;flex-direction: column;align-items: center;line-height: 70rpx;margin-bottom: 20rpx;">
			<image src="/static/pay/success.png" style="width: 145rpx;height: 184rpx;" mode="aspectFit"></image>
			<text>下单成功,请尽快支付!</text>
			<text>¥{{total_price}}</text>
			<view style="font-size: 24rpx;color: #898989;text-align: center;">
				<text>剩余支付时间</text>
				<uni-countdown background-color="#fff" :showDay="false" :minute="minute" :second="second">
				</uni-countdown>
			</view>
		</view>
		<view style="font-size: 30rpx;">
			<view class="item" style="line-height: 70rpx;">
				<text style="text-align: right;"> 提 货 人：</text>
				<input type="text" v-model="username" style="width: 75%;height: 35rpx;" placeholder="请输入提货人姓名"/>
			</view>
			<view class="item" style="line-height: 70rpx;">
				<text style="text-align: right;">手机号码：</text>
				<input type="text" v-model="tel" style="width: 75%;height: 35rpx;" placeholder="请输入手机号码"/>
			</view>
			<view style="line-height: 50rpx;">
				<view class="item">团长信息：{{community_info}}({{communityName}})</view>
				<view class="item">提货地点：{{ziti_address}}</view>
			</view>
		</view>
		
		
		<view class="order">
			<view class="it1">{{goods_count}}件商品</view>
			<block v-for="(item, index) in orderList" :key="index">
				<view>
					<view class="line"></view>
					<view style="display: flex;flex-direction: row;margin-left: 30rpx;">
						<image :src="item.image" style="width: 120rpx;height: 120rpx;"></image>
						<view style="display: flex;flex-direction: column;margin-left: 30rpx;">
							<text style="font-size: 28rpx;">{{item.name}}</text>
							<text style="font-size: 24rpx;color: #999999;">￥{{item.price}} x{{item.quantity}}</text>
							<view style="font-size: 24rpx;">小计：<text style="color: red;">￥{{item.total}}</text></view>
							<text style="font-size: 24rpx;color: red;">预计{{item.pick_up_time}}({{item.pick_up_weekday}})可自提</text>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view style="margin-bottom: 294rpx;">
			<text style="font-size: 30rpx;margin: 0 30rpx;">选择支付方式</text>
			<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;font-size: 30rpx;color: #1b1b1b;margin: 50rpx 30rpx 30rpx;">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<image class="pay" src="/static/pay/wechat.png" mode="aspectFit"></image>
					<text>微信</text>
				</view>
				<checkbox-group>
					<checkbox value="cb"></checkbox>
				</checkbox-group>
			</view>
			<!-- <view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;font-size: 30rpx;color: #1b1b1b;margin: 50rpx 30rpx 30rpx;">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<image class="pay" src="/static/pay/IDcard.png" mode="aspectFit"></image>
					<text>会员卡(余额<text style="color: #F96A5C;">¥256.36</text>)</text>
				</view>
				<checkbox-group>
					<checkbox value="cb"></checkbox>
				</checkbox-group>
			</view> -->
		</view>
		<button type="default" @click="toPay"
			style="position: fixed;bottom:0;right:0;width: 100%; border-radius: 0; height: 109rpx;background-color: #00C657;color: #fff;font-size: 32rpx;display: flex;justify-content: center;align-items: center;">立即支付({{total_price}})</button>
	</view>
</template>
<script>
	import {
		Storage
	} from '@/static/libs/utils.js'
	import { reallyBuy } from '@/utils/index.js'
	export default {
		data() {
			return {
				// username:'John',
				// tel:'17628292383',
				username:'',
				tel:'',
			    community_info:'',
				ziti_address:'',
				communityName:'',
				minute: 14,
				second: 58,
				show1: false,
				total_price: 200,
				goods_list: null,
				carts: '',
				comment:'',
				order_id:'',
				goods_count:'',
				orderList:[]
			};
		},
		onLoad(option) {
			// console.log(JSON.parse(option.totalPrice));
		    this.total_price = JSON.parse(option.totalPrice)
		    this.res.data.order_id = JSON.parse(option.res.data.order_id)
			this.getProductList();
		},
		// created(){
		// 	Storage.set('username')
		// 	console.log('提货人',username)
		// 	Storage.set('tel')
		// 	console.log('电话号码',tel)
		// },
		mounted() {
			this.getTeamInfo();
			this.getOrder();
		},
		methods: {
			getTeamInfo(){
				this.token = Storage.get('token')
				this.$request.get("/wxapp.php?from=wxapp&c=entry&a=wxapp&do=user",
				{
					controller:'index.get_firstload_msg',
					token:this.token,
					m:'lionfish_comshop'
					}).then(res=>{
						console.log('当前团长信息',res)
						this.ziti_address = res.data.default_head_info.fullAddress
						this.community_info = res.data.default_head_info.disUserName
						this.communityName = res.data.default_head_info.communityName
					})
			},
			//获取订单
			getOrder(){
				this.token = Storage.get('token')
				this.$request.get("/wxapp.php?from=wxapp&c=entry&a=wxapp&do=user&&m=lionfish_comshop&",
				{
					controller:'car.checkout',
					token:this.token,
					community_id:1,
					buy_type:'dan',
					soli_id:1
				}).then(res=>{
					console.log('获取订单',res)
					console.log(res.data.seller_goodss[0].goods[0].name)
					console.log(res.data.seller_goodss[0].total_quantity)
					this.goods_count = res.data.seller_goodss[0].total_quantity
					this.orderList = res.data.seller_goodss[0].goods
					console.log('订单列表',res.data.seller_goodss[0].goods)
				})
			},
			//发起支付
			//获取购物车商品信息
			getProductList() {
				this.token = Storage.get('token')
				var that = this;

				this.$request.get("/wxapp.php?from=wxapp&c=entry&a=wxapp&do=user&m=lionfish_comshop", {
					controller: 'car.show_cart_goods',
					token: this.token,
					community_id: 1,
					quantity: 1,
					buy_type: 'dan'
				}).then(res => {
					// var arr1 = {};
					// var arr2 = {};
					that.carts = JSON.parse(JSON.stringify(res.data.carts));
					// console.log(carts);
					// Object.keys(carts).forEach(kk => {
					// 	arr
					// });
					// console.log(arr1);
					// console.log('开始来了', res.data.carts);
					// arr1.map(v => {
					// 	arr2 = [...arr2, v.shopcarts]
					// })
					// that.carts = arr2;
					 that.submitOrder();
					// for (var i in res.data.carts) {
					// 	// console.log('in in',res.data.carts[i].shopcarts);
					// 	// if(res.data.carts[i].shopcarts){
					// 	//  aaaass = [...aaaass,res.data.carts[i].shopcarts];
					// 	// } 
					// 	arr.push(res.data.carts[i]);
					// }
					// console.log(arr, 11111111111111);
					// that.goods_list = res.data.carts;

					// console.log('last来了11', that.goods_list);
				})
			},
			//提交订单
			reallyBuy,
			submitOrder() {
				let arr = [];
				let commentArr = [];
				var seller_goodss = this.carts;
				console.log(seller_goodss, 1111111);
				console.log('seller_goodss啦啦啦啦', seller_goodss);
				for (let key in seller_goodss) {
					console.log(key,'key=============');
					let goodsid = '';
					let shopcarts = seller_goodss[key].shopcarts;
					Object.keys(shopcarts).forEach(kk => {
						goodsid += shopcarts[kk].id + '_';
					})
					commentArr[key] = key + '_' + goodsid ;//+ commentArr[key]
				}
				for (let key in commentArr) {
					arr.push(commentArr[key]);
				};
				console.log('seller_goodss啦啦啦啦2', arr);
				let comment = arr.join('@EOF@');
				// console.log('commentfafafafaaaa', comment);
				this.comment = comment;
			},
			toPay() {
				uni.showLoading({
					title:"加载中...",
					duration:3000
				})
				//发起微信支付
				//console.log('51515151',this.goods_list);return;
				var that = this
				this.token = Storage.get('token')
				this.$request.get("/wxapp.php?from=wxapp&c=entry&a=wxapp&do=user&&m=lionfish_comshop", {
					controller: 'car.sub_order',
					token: this.token,
					pay_method: 'wxpay',
					buy_type: 'dan',
					pick_up_id: 1,
					dispatching: 'pickup',
					ziti_name: this.username,
					comment: this.comment,
					ziti_mobile: this.tel,
					ck_yupay: 0,
					use_score: 0
				}).then(res => {
					var obj = res.data;
					//var order_id = res.data.order_id
					 console.log('订单id',res.data.order_id)
					 that.reallyBuy(obj,res.data.order_id,0);
				})
			}
		}
	};
</script>
<style lang="scss">
    .radio {
		width: 40rpx;
		height: 40rpx;
	}
	.pay {
		width: 54rpx;
		height: 54rpx;
		margin-right: 20rpx;
	}
	.sj {
		width: 36rpx;
		height: 36rpx;
		border-radius: 4rpx;
		color: #fff;
		background-color: #000;
		padding: 6rpx;
	}
	checkbox .wx-checkbox-input {
		border-color: #D4D4D4;
		border-radius: 50%;
	}
	checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		color: #fff;
		background: #00C657;
	}
	.item {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 30rpx;
	}
	.order {
		width: 700rpx;
		margin: 25rpx 25rpx 10%;
		border-radius: 20rpx;
		border: 1px solid #F7F7F7;
		padding-bottom: 30rpx;
	}
	.it1 {
		margin-left: 550rpx;
		padding-top: 30rpx;
		color: #999999;
		font-size: 24rpx;
	}
	.line {
		width: 100%;
		height: 1rpx;
		background-color: #F7F7F7;
		margin: 20rpx 0rpx;
	}
</style>
